package com.dxt.dao;

import com.dxt.pojo.User;
import com.dxt.utils.JDBCUtil;
import com.dxt.utils.MD5Util;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * BelongProject: deliveryManage
 * BelongPackage: com.dxt.dao
 * Description:
 *
 * @Author 段鑫涛
 * @Create 2025/3/30 21:58
 * @Version 1.0
 */
public class UserDaoImpl implements UserDao{
    @Override
    public User getUserByUsername(String username) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(JDBCUtil.getDataSource());
        String sql = "select * from sys_user where username=?";
        return queryRunner.query(sql, new BeanHandler<User>(User.class), username);
    }

    @Override
    public void UpdatePassword(String newPassword, Integer id) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(JDBCUtil.getDataSource());
        String sql = "update sys_user set password=? where id=?";
        queryRunner.update(sql, MD5Util.encrypt(newPassword),id);
    }
}
